﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Softserve.NumberToWords.Abstract;

namespace Softserve.NumberToWords.Concrete
{
    class EnglishDictionary : ConvertDictionaryBase
    {
        #region Const
        private const string generalTemplate = " ";
        private const string teenTemplate = "{0}{1}";
        private const string DecimalTemplate = "{0} {1}";
        public readonly Dictionary<int, string> ExceptionNumbers = default(Dictionary<int, string>);
        #endregion

        #region Ctor
        public EnglishDictionary()
        {
            FirstNumbers = new List<string>() 
             {
                 "zero",
                 "one", 
                 "two",
                 "three",
                 "four",
                 "five", 
                 "six", 
                 "seven", 
                 "eight", 
                 "nine", 
                 "ten", 
                 "eleven", 
                 "twelve", 
                 "thirteen" 
             };
            Teen = new List<string>() 
             { 
                 "teen", 
                 "hundred",
                 "thousand", 
                 "million", 
                 "billion"
             };
            DecimalNumbers = new List<string>() 
             { 
                 "twenty", 
                 "thirty", 
                 "fourty", 
                 "fifty", 
                 "sixty", 
                 "seventy", 
                 "eighty", 
                 "ninety" 
             };
            TeenNumbersCount = (byte)(19 - FirstNumbers.Count);
            ExceptionNumbers = new Dictionary<int, string>();
            ExceptionNumbers.Add(15, "fifteen");
            GeneralTemplate = generalTemplate;
        } 
        #endregion

        #region ConvertBase Implementation
        public override string GetDecimalNumber(int number)
        {
            if (number > 19)
            {
                byte dec = (byte)(number / 10);
                string s = string.Format(DecimalTemplate, DecimalNumbers[dec - 2], FirstNumbers[number - dec * 10]);
                return s;
            }
            return null;
        }


        public override string GetTeenNumber(int number)
        {
            if (number < 20 && !ExceptionNumbers.ContainsKey(number))
            {
                if (number < 14)
                {
                    return FirstNumbers[number];
                }
                else
                {
                    return string.Format(teenTemplate, FirstNumbers[number - 10], Teen[0]);
                }
            }
            if (ExceptionNumbers.ContainsKey(number))
            {
                return ExceptionNumbers[number];
            }
            return null;
        } 
        #endregion
    }
}
